class Vector2D:
    def __init__(self, x, y):
        self.x = x
        self.y = y

    def __add__(self, other):
        return Vector2D(
            self.x + other.x,
            self.y + other.y
        )

    def __abs__(self):
        """计算向量的长度（模）：abs(v)"""
        return (self.x**2 + self.y**2) ** 0.5

    def __bool__(self):
        """判断向量是否为零向量：bool(v)"""
        return self.x != 0 or self.y != 0

    def __getitem__(self, index):
        """支持索引访问：v[0]、v[1]"""
        if index == 0:
            return self.x
        elif index == 1:
            return self.y

    def __len__(self):
        """返回向量的维度：len(v)"""
        return 2



# 测试向量运算
v1 = Vector2D(3, 4)
v2 = Vector2D(1, 2)
v = v1 + v2
print(f"({v.x}, {v.y})")

v = Vector2D(3, 4)
print(abs(v))
# 输出: 5.0 (即向量的长度)
print(bool(v))
# 输出: True (非零向量)
print(bool(Vector2D(0, 0)))
# 输出: False (零向量)
